package com.vrv.drools.droolsdemo.controller;

import com.vrv.drools.droolsdemo.domain.DroolsRule;
import com.vrv.drools.droolsdemo.service.DroolsRuleService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (DroolsRule)表控制层
 *
 * @author makejava
 * @since 2023-11-01 10:42:49
 */
@RestController
@RequestMapping("droolsRule")
public class DroolsRuleController {
    /**
     * 服务对象
     */
    @Resource
    private DroolsRuleService droolsRuleService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<List<DroolsRule>> list() {
        return ResponseEntity.ok(this.droolsRuleService.list());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<DroolsRule> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.droolsRuleService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param droolsRule 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Boolean> add(DroolsRule droolsRule) {
        boolean save = this.droolsRuleService.save(droolsRule);
        return ResponseEntity.ok(save);
    }

    /**
     * 编辑数据
     *
     * @param droolsRule 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Boolean> edit(DroolsRule droolsRule) {
        return ResponseEntity.ok(this.droolsRuleService.updateById(droolsRule));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.droolsRuleService.removeById(id));
    }

}

